import 'package:jet_rails/jr_app/jr_models/jr_media_model.dart';
import 'package:json_annotation/json_annotation.dart';

part 'jr_user_model.g.dart';

@JsonSerializable()
class JrUserModel {
  String? activityTagUrl;
  int? age;
  String? avatar;
  String? avatarMapPath;
  int? callCoins;
  String? country;
  int? followNum;
  int? gender;
  String? nickname;
  String? status;
  String? unit;
  String userId;
  List? videoMapPaths;
  int? userType;
  String? avatarUrl;
  String? birthday;
  String? language;
  String? about;
  bool? isSpecialFollow;
  String? onlineStatus;
  int? level;
  bool? isVip;
  String? registerCountry;
  String? broadcasterId;
  String? alias;

  JrUserModel({
    this.level,
    this.onlineStatus,
    this.isSpecialFollow,
    this.about,
    this.birthday,
    this.language,
    this.avatarUrl,
    this.userType,
    this.isVip,
    this.activityTagUrl,
    this.age,
    this.avatar,
    this.avatarMapPath,
    this.callCoins,
    this.country,
    this.followNum,
    this.gender,
    this.nickname,
    this.status,
    this.unit,
    this.userId = '',
    this.videoMapPaths,
    this.registerCountry,
    this.broadcasterId,
    this.alias,
  });

  String get getAvatarUrl {
    if (avatarUrl != null && avatarUrl!.isNotEmpty) {
      return avatarUrl!;
    } else if (avatar != null && avatar!.isNotEmpty) {
      return avatar!;
    } else {
      return '';
    }
  }

  String get getId => userId.isNotEmpty ? userId : (broadcasterId ?? '');

  factory JrUserModel.fromJson(Map<String, dynamic> json) => _$JrUserModelFromJson(json);

  Map<String, dynamic> toJson() => _$JrUserModelToJson(this);
}

@JsonSerializable()
class JrLoginUserModel {
  String? token;
  String? isFirstRegister;
  String? userId;
  String? avatarUrl;
  String? avatarMiddleThumbUrl;
  String? avatarThumbUrl;
  int? gender;
  String? nickname;
  int? age;
  String? birthday;
  String? country;
  String? language;
  String? about;
  bool? isVip;
  String? vipLevel;
  String? vipExpiryTime;
  bool? isBlock;
  bool? isFriend;
  String? onlineStatus;
  String? rongcloudToken;
  List<JrMediaModel>? mediaList;
  int availableCoins;

  JrLoginUserModel({
    this.about,
    this.age,
    this.avatarMiddleThumbUrl,
    this.avatarThumbUrl,
    this.avatarUrl,
    this.birthday,
    this.availableCoins = 0,
    this.country,
    this.language,
    this.gender,
    this.isBlock,
    this.isFirstRegister,
    this.isFriend,
    this.isVip,
    this.mediaList,
    this.nickname,
    this.onlineStatus,
    this.rongcloudToken,
    this.token,
    this.userId,
    this.vipExpiryTime,
    this.vipLevel,
  });

  String get getAvatarUrl => avatarUrl ?? '';

  factory JrLoginUserModel.empty() => JrLoginUserModel();

  factory JrLoginUserModel.fromJson(Map<String, dynamic> json) => _$JrLoginUserModelFromJson(json);

  Map<String, dynamic> toJson() => _$JrLoginUserModelToJson(this);
}